/*
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#include <hash_map>
#include <set>
#include <vector>
#include <Stack>
#include <iostream>
#include <sstream>
using namespace std;

struct ListNode{
	int val;
	ListNode *next;
	ListNode(int x):val(x),next(NULL){}
};

ListNode * generateList(int a[],int len){
	ListNode *head=NULL,*q;
	for(int i=0;i<len;i++){
		ListNode *p=new ListNode(a[i]);
		if(!head){
			head=p;
			q=p;
		}else{
			q->next=p;
			q=p;
		}
	}
	return head;
}
void print(ListNode *p){
	while(p){
		cout<<p->val<<"->";
		p=p->next;
	}
	cout<<endl;
}
ListNode* deleteDuplicates(ListNode* head) {
	ListNode *p=head,*q;
	if(head==NULL)
		return head;
	q=head->next;
	bool flag=true;
	while(q){
		if(q->val!=p->val){
			p->next=q;
			p=q;
			flag=false;
		}else
			flag=true;
		q=q->next;
	}
	if(flag){
		p->next=NULL;
	}
	return head;
}
int main(){
	int a[]={1,1,1,2,2};
	ListNode *p=generateList(a,sizeof(a)/sizeof(int));
	print(p);
	ListNode *q=deleteDuplicates(p);
	print(q);
	cout<<endl;
	system("pause");
}
*/